package com.davinci.servicedesk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.davinci.servicedesk.library.UserFunctions;

public class DashboardActivity extends Activity {
	UserFunctions userFunctions;
	Button btnLogout;
	
	private static String TAG_PEMAIL = "pemail";
	private static String TAG_DEMAIL = "demail";
	
	String pemail;

	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        /**
         * Dashboard Screen for the application
         * */        
        // Check login status in database
        userFunctions = new UserFunctions();
        if(userFunctions.isUserLoggedIn(getApplicationContext())){
        	setContentView(R.layout.dashboard);
        	

        	
			Intent i = getIntent();
			
			// getting product id (pid) from intent
			pemail = i.getStringExtra(TAG_PEMAIL);
        	
    		TextView txtEmail = (TextView) findViewById(R.id.email);
    		txtEmail.setText((CharSequence) pemail);
        	
        	
        	btnLogout = (Button) findViewById(R.id.uitloggen);
        	
        	btnLogout.setOnClickListener(new View.OnClickListener() {
    			
    			public void onClick(View arg0) {
    				// TODO Auto-generated method stub
    				userFunctions.logoutUser(getApplicationContext());
    				Intent login = new Intent(getApplicationContext(), LoginActivity.class);
    	        	login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    	        	startActivity(login);
    	        	// Closing dashboard screen
    	        	finish();
    			}
    		});
        	
        }else{
        	// user is not logged in show login screen
        	Intent login = new Intent(getApplicationContext(), LoginActivity.class);
        	login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        	startActivity(login);
        	// Closing dashboard screen
        	finish();
        }
        
        Button klanten = (Button) findViewById(R.id.klanten);
        klanten.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), KlantenOverzicht.class);
                startActivityForResult(myIntent, 0);
            }
        });
        
        Button nieuw = (Button) findViewById(R.id.nieuw_incident);
        nieuw.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), Incidenten01.class);
                
    			   			

                
                startActivityForResult(myIntent, 0);
            }
        });

        
        Button incidenten = (Button) findViewById(R.id.openstaande_incidenten);
        incidenten.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), IncidentenOverzicht.class);
                String demail = pemail;
    			// getting product id (pid) from intent
    			myIntent.putExtra(TAG_DEMAIL, demail);
    			
                startActivityForResult(myIntent, 0);
            }
        });
        
    }
}